import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.List;

public class RedisDemoList {
    public static void test1(Jedis jedis) {
        System.out.println("lpush  lrange:");
        jedis.flushAll();
        jedis.lpush("key","1","2","3","4","5","6","7","8","9");
        List<String> list = jedis.lrange("key",0,-1);
        System.out.println(list);
    }
    public static void test2(Jedis jedis) {
        System.out.println("rpush:");
        jedis.flushAll();
        jedis.rpush("key","1","2","3","4","5");
        List<String> list = jedis.lrange("key",0,-1);
        System.out.println(list);
    }
    public static void test3(Jedis jedis) {
        System.out.println("lpop:");
        jedis.flushAll();
        jedis.rpush("key","1","2","3","4","5");
        List<String> list = jedis.lrange("key",0,-1);
        System.out.println(list);
        String result=jedis.lpop("key");
        list = jedis.lrange("key",0,-1);
        System.out.println(list);
        for (int i = 0; i < 5; i++) {
            String x = jedis.lpop("key");
            System.out.println(x);

        }

    }
    public static void test4(Jedis jedis) {
        System.out.println("rpop:");
        jedis.flushAll();
        jedis.rpush("key","1","2","3","4","5");
        for (int i = 0; i < 6; i++) {
            String x = jedis.rpop("key");
            System.out.println(x);
        }
    }
    public static void test5(Jedis jedis) {
        System.out.println("blpop:");
        jedis.flushAll();
        //返回结果是二元组，第一个是弹出的哪个key，第二个是弹出的value
        List<String>result =jedis.blpop(100,"key");
        System.out.println(result.get(0));
        System.out.println(result.get(1));
    }
    public static void test6(Jedis jedis) {
        System.out.println("llen:");
        jedis.flushAll();
        jedis.rpush("key","1","2","3","4","5");
        long length=jedis.llen("key");
        System.out.println(length);
    }
    public static void main(String[] args) {
        JedisPool jedisPool = new JedisPool("127.0.0.1", 8888);
            try (Jedis jedis = jedisPool.getResource()) {
                test6(jedis);
            }

    }
}
